locals {
  cce_groups = {
    myapp = {
      cluster_name           = "cce-baidu-myapp-dev"
      cluster_version        = "v1.23"
      flavor_id              = "cce.s1.small"
      vpc_id                 = data.terraform_remote_state.vpc.outputs.vpc_info.id
      subnet_id              = data.terraform_remote_state.subnet.outputs.subnet_info["subnet-me212-dev-baidu_hub-cce-myapp"].id
      container_network_type = "vpc-router"
      kube_proxy_mode        = "ipvs"
    }
  }

  flattened_cce_groups = flatten([
    for group, config in local.cce_groups : {
      group                  = group
      cluster_name           = config.cluster_name
      cluster_version        = config.cluster_version
      flavor_id              = config.flavor_id
      vpc_id                 = config.vpc_id
      subnet_id              = config.subnet_id
      container_network_type = config.container_network_type
      kube_proxy_mode        = config.kube_proxy_mode
    }
  ])
}

module "cce" {
  source   = "../../../modules/cce"
  for_each = { for cce in local.flattened_cce_groups : cce.group => cce }

  cluster_name           = each.value.cluster_name
  cluster_version        = each.value.cluster_version
  flavor_id              = each.value.flavor_id
  vpc_id                 = each.value.vpc_id
  subnet_id              = each.value.subnet_id
  container_network_type = each.value.container_network_type
  kube_proxy_mode        = each.value.kube_proxy_mode
}